package com.xyht.sca_s.student_manage_system.modules.stampManagement.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.stampManagement.entity.dto.SmsStampUseLogAddDto;
import com.xyht.sca_s.student_manage_system.modules.stampManagement.service.SmsStampUseLogService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.xyht.sca_s.student_manage_system.auth.constant.CommonConstant.CLIENT_HEADER;

/**
 * <p>
 * 印章使用记录表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-05-31
 */
@RestController
@RequestMapping("/stampManagement/smsStampUseLog")
@SecretBody
public class SmsStampUseLogController {

    @Resource
    private SmsStampUseLogService smsStampUseLogService;

    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加印章使用记录")
    @PostMapping("/add")
    public ResponseResult addStampUseLog(HttpServletRequest request, @RequestBody SmsStampUseLogAddDto smsStampUseLogAddDto){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        String client = request.getHeader(CLIENT_HEADER);
        return smsStampUseLogService.addStampUseLog(userId,client,smsStampUseLogAddDto);
    }

    @ApiModelProperty("获取印章使用记录")
    @GetMapping("/list")
    public ResponseResult getStampUseLogList(@RequestParam(value = "beginTime",required = false) String beginTime,
                                            @RequestParam(value = "endTime",required = false) String endTime,
                                            @RequestParam(value = "userName",required = false) String userName,
                                            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return smsStampUseLogService.getStampUseLogList(beginTime,endTime,userName,pageSize,pageNum);
    }

    @ApiModelProperty("获取印章使用详情")
    @GetMapping("/detail")
    public ResponseResult getStampUseLogDetail(@RequestParam(value = "id",required = false)String id){
        return smsStampUseLogService.getStampUseLogDetail(id);
    }

}

